package com.findme.fecedetection.utlis

import com.tanguy.user.App.Companion.app
import java.math.BigInteger
import java.security.MessageDigest

/**
 *
 */
object Error {
    val REQUEST_ERROR = "请求出错！"
    val PARSER_ERROR = "数据解析出错！"
    val NET_ERROR = "网络异常，请检查您的网络状态！"
    val SERVER_ERROR = "服务器异常，请稍后重试！"
}

fun getMD5(str: String): String {
    return try {
        // 生成一个MD5加密计算摘要
        val md = MessageDigest.getInstance("MD5")
        // 计算md5函数
        md.update(str.toByteArray())
        // digest()最后确定返回md5 hash值，返回值为8为字符串。因为md5 hash值是16位的hex值，实际上就是8位的字符
        // BigInteger函数则将8位的字符串转换成16位hex值，用字符串来表示；得到字符串形式的hash值
        BigInteger(1, md.digest()).toString(16)
    } catch (e: Exception) {
        ""
    }
}

fun getStringType(typeCode: String, code: String) :String?{
    val hashMap = app.map[typeCode]
    if (hashMap != null) {
        return hashMap[code]
    }
    return null
}
fun getStringKey(typeCode: String, code: String) :String?{
    val hashMap = app.map[typeCode]
    if (hashMap != null) {
        return hashMap[code]
    }
    return null
}
fun getValuesList(typeCode: String) :ArrayList<String>{
    val arrayList = ArrayList<String>()
    val hashMap = app.map[typeCode]
    if (hashMap != null) {
        arrayList.addAll(hashMap.values)
    }
    return arrayList
}
fun getKeysList(typeCode: String) :ArrayList<String>{
    val arrayList = ArrayList<String>()
    val hashMap = app.map[typeCode]
    if (hashMap != null) {
        arrayList.addAll(hashMap.keys)
    }
    return arrayList
}